/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */
/**
 * Licensee: nu uc
 * License Type: Evaluation
 */
package org.testis.orm.classes;

import org.orm.*;

public class T_dmap_designtree {

    public T_dmap_designtree() {
    }

    public boolean save() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .saveObject(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean delete() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .deleteObject(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean refresh() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .getSession().refresh(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean evict() throws PersistentException {
	try {
	    org.testis.orm.manager.TestisDbPersistentManager.instance()
		    .getSession().evict(this);
	    return true;
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean deleteAndDissociate() throws PersistentException {
	try {
	    if (getParent() != null) {
		getParent().t_dmap_designtree.remove(this);
	    }

	    if (getObject() != null) {
		getObject().t_dmap_designtree.remove(this);
	    }

	    if (getClone() != null) {
		getClone().t_dmap_designtree1.remove(this);
	    }

	    if (getFirmware() != null) {
		getFirmware().t_dmap_designtree.remove(this);
	    }

	    if (getPreviousNode() != null) {
		getPreviousNode().t_dmap_designtree2.remove(this);
	    }

	    org.testis.orm.classes.T_bed_firmware[] lT_bed_firmwares = t_bed_firmware
		    .toArray();
	    for (int i = 0; i < lT_bed_firmwares.length; i++) {
		lT_bed_firmwares[i].setDeviceMap(null);
	    }
	    org.testis.orm.classes.T_dmap_designtree[] lT_dmap_designtrees = t_dmap_designtree
		    .toArray();
	    for (int i = 0; i < lT_dmap_designtrees.length; i++) {
		lT_dmap_designtrees[i].setParent(null);
	    }
	    org.testis.orm.classes.T_dmap_designtree[] lT_dmap_designtree1s = t_dmap_designtree1
		    .toArray();
	    for (int i = 0; i < lT_dmap_designtree1s.length; i++) {
		lT_dmap_designtree1s[i].setClone(null);
	    }
	    org.testis.orm.classes.T_dmap_designtree[] lT_dmap_designtree2s = t_dmap_designtree2
		    .toArray();
	    for (int i = 0; i < lT_dmap_designtree2s.length; i++) {
		lT_dmap_designtree2s[i].setPreviousNode(null);
	    }
	    return delete();
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    public boolean deleteAndDissociate(org.orm.PersistentSession session)
	    throws PersistentException {
	try {
	    if (getParent() != null) {
		getParent().t_dmap_designtree.remove(this);
	    }

	    if (getObject() != null) {
		getObject().t_dmap_designtree.remove(this);
	    }

	    if (getClone() != null) {
		getClone().t_dmap_designtree1.remove(this);
	    }

	    if (getFirmware() != null) {
		getFirmware().t_dmap_designtree.remove(this);
	    }

	    if (getPreviousNode() != null) {
		getPreviousNode().t_dmap_designtree2.remove(this);
	    }

	    org.testis.orm.classes.T_bed_firmware[] lT_bed_firmwares = t_bed_firmware
		    .toArray();
	    for (int i = 0; i < lT_bed_firmwares.length; i++) {
		lT_bed_firmwares[i].setDeviceMap(null);
	    }
	    org.testis.orm.classes.T_dmap_designtree[] lT_dmap_designtrees = t_dmap_designtree
		    .toArray();
	    for (int i = 0; i < lT_dmap_designtrees.length; i++) {
		lT_dmap_designtrees[i].setParent(null);
	    }
	    org.testis.orm.classes.T_dmap_designtree[] lT_dmap_designtree1s = t_dmap_designtree1
		    .toArray();
	    for (int i = 0; i < lT_dmap_designtree1s.length; i++) {
		lT_dmap_designtree1s[i].setClone(null);
	    }
	    org.testis.orm.classes.T_dmap_designtree[] lT_dmap_designtree2s = t_dmap_designtree2
		    .toArray();
	    for (int i = 0; i < lT_dmap_designtree2s.length; i++) {
		lT_dmap_designtree2s[i].setPreviousNode(null);
	    }
	    try {
		session.delete(this);
		return true;
	    } catch (Exception e) {
		return false;
	    }
	} catch (Exception e) {
	    e.printStackTrace();
	    throw new PersistentException(e);
	}
    }

    private java.util.Set this_getSet(int key) {
	if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_T_BED_FIRMWARE) {
	    return ORM_t_bed_firmware;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_T_DMAP_DESIGNTREE) {
	    return ORM_t_dmap_designtree;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_T_DMAP_DESIGNTREE1) {
	    return ORM_t_dmap_designtree1;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_T_DMAP_DESIGNTREE2) {
	    return ORM_t_dmap_designtree2;
	}

	return null;
    }

    private void this_setOwner(Object owner, int key) {
	if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_PARENT) {
	    this.Parent = (org.testis.orm.classes.T_dmap_designtree) owner;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_OBJECT) {
	    this.Object = (org.testis.orm.classes.T_dmap_objects) owner;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_CLONE) {
	    this.Clone = (org.testis.orm.classes.T_dmap_designtree) owner;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_FIRMWARE) {
	    this.Firmware = (org.testis.orm.classes.T_bed_firmware) owner;
	} else if (key == org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_PREVIOUSNODE) {
	    this.PreviousNode = (org.testis.orm.classes.T_dmap_designtree) owner;
	}
    }

    org.orm.util.ORMAdapter _ormAdapter = new org.orm.util.AbstractORMAdapter() {

	public java.util.Set getSet(int key) {
	    return this_getSet(key);
	}

	public void setOwner(Object owner, int key) {
	    this_setOwner(owner, key);
	}
    };
    private int id;
    private org.testis.orm.classes.T_dmap_designtree Parent;
    private org.testis.orm.classes.T_dmap_objects Object;
    private org.testis.orm.classes.T_dmap_designtree Clone;
    private org.testis.orm.classes.T_bed_firmware Firmware;
    private org.testis.orm.classes.T_dmap_designtree PreviousNode;
    private java.util.Set ORM_t_bed_firmware = new java.util.HashSet();
    private java.util.Set ORM_t_dmap_designtree = new java.util.HashSet();
    private java.util.Set ORM_t_dmap_designtree1 = new java.util.HashSet();
    private java.util.Set ORM_t_dmap_designtree2 = new java.util.HashSet();

    private void setId(int value) {
	this.id = value;
    }

    public int getId() {
	return id;
    }

    public int getORMID() {
	return getId();
    }

    public void setRank(Integer rank) throws PersistentException {
	if (rank != null) {
	    T_dmap_designtreeCriteria criteria = new T_dmap_designtreeCriteria();
	    criteria.id.eq(rank);
	    setPreviousNode(criteria.uniqueT_dmap_designtree());
	} else {
	    setPreviousNode(null);
	}
    }

    public Integer getRank() {
	if (getPreviousNode() != null) {
	    return getPreviousNode().getId();
	} else {
	    return null;
	}
    }

    public void removeClone() {
	if (Clone != null) {
	    Clone.t_dmap_designtree1.remove(this);
	}
    }

    public void setParent(org.testis.orm.classes.T_dmap_designtree value) {
	if (Parent != null) {
	    Parent.t_dmap_designtree.remove(this);
	}
	if (value != null) {
	    value.t_dmap_designtree.add(this);
	}
    }

    public org.testis.orm.classes.T_dmap_designtree getParent() {
	return Parent;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_Parent(
	    org.testis.orm.classes.T_dmap_designtree value) {
	this.Parent = value;
    }

    private org.testis.orm.classes.T_dmap_designtree getORM_Parent() {
	return Parent;
    }

    public void setObject(org.testis.orm.classes.T_dmap_objects value) {
	if (Object != null) {
	    Object.t_dmap_designtree.remove(this);
	}
	if (value != null) {
	    value.t_dmap_designtree.add(this);
	}
    }

    public org.testis.orm.classes.T_dmap_objects getObject() {
	return Object;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_Object(org.testis.orm.classes.T_dmap_objects value) {
	this.Object = value;
    }

    private org.testis.orm.classes.T_dmap_objects getORM_Object() {
	return Object;
    }

    public void setClone(org.testis.orm.classes.T_dmap_designtree value) {
	if (Clone != null) {
	    Clone.t_dmap_designtree1.remove(this);
	}
	if (value != null) {
	    value.t_dmap_designtree1.add(this);
	}
    }

    public org.testis.orm.classes.T_dmap_designtree getClone() {
	return Clone;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_Clone(
	    org.testis.orm.classes.T_dmap_designtree value) {
	this.Clone = value;
    }

    private org.testis.orm.classes.T_dmap_designtree getORM_Clone() {
	return Clone;
    }

    public void setFirmware(org.testis.orm.classes.T_bed_firmware value) {
	if (Firmware != null) {
	    Firmware.t_dmap_designtree.remove(this);
	}
	if (value != null) {
	    value.t_dmap_designtree.add(this);
	}
    }

    public org.testis.orm.classes.T_bed_firmware getFirmware() {
	return Firmware;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_Firmware(
	    org.testis.orm.classes.T_bed_firmware value) {
	this.Firmware = value;
    }

    private org.testis.orm.classes.T_bed_firmware getORM_Firmware() {
	return Firmware;
    }

    public void setPreviousNode(
	    org.testis.orm.classes.T_dmap_designtree value) {
	if (PreviousNode != null) {
	    PreviousNode.t_dmap_designtree2.remove(this);
	}
	if (value != null) {
	    value.t_dmap_designtree2.add(this);
	}
    }

    public org.testis.orm.classes.T_dmap_designtree getPreviousNode() {
	return PreviousNode;
    }

    /**
     * This method is for internal use only.
     */
    private void setORM_PreviousNode(
	    org.testis.orm.classes.T_dmap_designtree value) {
	this.PreviousNode = value;
    }

    private org.testis.orm.classes.T_dmap_designtree getORM_PreviousNode() {
	return PreviousNode;
    }

    private void setORM_T_bed_firmware(java.util.Set value) {
	this.ORM_t_bed_firmware = value;
    }

    private java.util.Set getORM_T_bed_firmware() {
	return ORM_t_bed_firmware;
    }

    public final org.testis.orm.classes.T_bed_firmwareSetCollection t_bed_firmware = new org.testis.orm.classes.T_bed_firmwareSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_T_BED_FIRMWARE,
	    org.testis.orm.manager.ORMConstants.KEY_T_BED_FIRMWARE_DEVICEMAP,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    private void setORM_T_dmap_designtree(java.util.Set value) {
	this.ORM_t_dmap_designtree = value;
    }

    private java.util.Set getORM_T_dmap_designtree() {
	return ORM_t_dmap_designtree;
    }

    public final org.testis.orm.classes.T_dmap_designtreeSetCollection t_dmap_designtree = new org.testis.orm.classes.T_dmap_designtreeSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_T_DMAP_DESIGNTREE,
	    org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_PARENT,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    private void setORM_T_dmap_designtree1(java.util.Set value) {
	this.ORM_t_dmap_designtree1 = value;
    }

    private java.util.Set getORM_T_dmap_designtree1() {
	return ORM_t_dmap_designtree1;
    }

    public final org.testis.orm.classes.T_dmap_designtreeSetCollection t_dmap_designtree1 = new org.testis.orm.classes.T_dmap_designtreeSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_T_DMAP_DESIGNTREE1,
	    org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_CLONE,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    private void setORM_T_dmap_designtree2(java.util.Set value) {
	this.ORM_t_dmap_designtree2 = value;
    }

    private java.util.Set getORM_T_dmap_designtree2() {
	return ORM_t_dmap_designtree2;
    }

    public final org.testis.orm.classes.T_dmap_designtreeSetCollection t_dmap_designtree2 = new org.testis.orm.classes.T_dmap_designtreeSetCollection(
	    this,
	    _ormAdapter,
	    org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_T_DMAP_DESIGNTREE2,
	    org.testis.orm.manager.ORMConstants.KEY_T_DMAP_DESIGNTREE_PREVIOUSNODE,
	    org.testis.orm.manager.ORMConstants.KEY_MUL_ONE_TO_MANY);

    public String toString() {
	return toString(false);
    }

    public String toString(boolean idOnly) {
	if (idOnly) {
	    return String.valueOf(getId());
	} else {
	    StringBuffer sb = new StringBuffer();
	    sb.append("T_dmap_designtree[ ");
	    sb.append("Id=").append(getId()).append(" ");
	    if (getParent() != null) {
		sb.append("Parent.Persist_ID=")
			.append(getParent().toString(true)).append(" ");
	    } else {
		sb.append("Parent=null ");
	    }
	    if (getObject() != null) {
		sb.append("Object.Persist_ID=")
			.append(getObject().toString(true)).append(" ");
	    } else {
		sb.append("Object=null ");
	    }
	    if (getClone() != null) {
		sb.append("Clone.Persist_ID=")
			.append(getClone().toString(true)).append(" ");
	    } else {
		sb.append("Clone=null ");
	    }
	    if (getFirmware() != null) {
		sb.append("Firmware.Persist_ID=")
			.append(getFirmware().toString(true)).append(" ");
	    } else {
		sb.append("Firmware=null ");
	    }
	    if (getPreviousNode() != null) {
		sb.append("PreviousNode.Persist_ID=")
			.append(getPreviousNode().toString(true)).append(" ");
	    } else {
		sb.append("PreviousNode=null ");
	    }
	    sb.append("T_bed_firmware.size=").append(t_bed_firmware.size())
		    .append(" ");
	    sb.append("T_dmap_designtree.size=")
		    .append(t_dmap_designtree.size()).append(" ");
	    sb.append("T_dmap_designtree1.size=")
		    .append(t_dmap_designtree1.size()).append(" ");
	    sb.append("T_dmap_designtree2.size=")
		    .append(t_dmap_designtree2.size()).append(" ");
	    sb.append("]");
	    return sb.toString();
	}
    }
}
